﻿Public Class FormTipoEmpListado
    Dim classController As New Class_RC_Controller.rc_Empleados()

    Private m_frmtipoemp As FrmTipoEmp
    Public Property frmtipoemp() As FrmTipoEmp
        Get
            Return m_frmtipoemp
        End Get
        Set(ByVal value As FrmTipoEmp)
            m_frmtipoemp = value
        End Set
    End Property
    Private Sub FormTipoEmpListado_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dgTipoEmp.AutoGenerateColumns = False
        CargarTipoEmp()
    End Sub
    Private Sub CargarTipoEmp()
        Dim dt As New DataTable
        dt = classController.get_TipoEmpleado_All(oiml.dbConn, 0, txtDescripcion.Text)
        dgTipoEmp.DataSource = dt
    End Sub


    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()
    End Sub

    Private Sub txtBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBuscar.Click
        CargarTipoEmp()
    End Sub


    Private Sub btnEditar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditar.Click
        Try
            If dgTipoEmp.SelectedRows.Count > 0 Then
                Dim Cod As New Integer
                Cod = dgTipoEmp.SelectedRows(0).Cells(0).Value

                If frmtipoemp Is Nothing Then
                    frmtipoemp = New FrmTipoEmp
                    frmtipoemp.codTipoEmp = Cod
                    'If frmServicios.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    frmtipoemp.ShowDialog()
                    CargarTipoEmp()
                    frmtipoemp.Dispose()
                    frmtipoemp = Nothing
                    'End If
                Else
                    frmtipoemp.codTipoEmp = Cod
                    frmtipoemp.ShowDialog()
                End If

            End If

        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try
    End Sub
    Private Sub dgTipoEmp_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgTipoEmp.DoubleClick
        btnEditar_Click(sender, e)
    End Sub
    Private Sub txtDescripcion_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyCode = Keys.Enter Then
            CargarTipoEmp()

        End If
    End Sub

    Private Sub dgTipoEmp_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgTipoEmp.KeyDown
        If e.KeyCode = Keys.Enter Then
            btnEditar_Click(sender, e)
        End If
    End Sub

    Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click
        '    If frmciudad Is Nothing Then
        frmtipoemp = New FrmTipoEmp()
        frmtipoemp.ShowDialog()
        CargarTipoEmp()
    End Sub
End Class